package parser;

import antlr.RecognitionException;
import antlr.Token;

class ReturnStmt extends Stmt {

    Expr value;
    int protection_depth;

    ReturnStmt(Expr value, int protection_depth) {
        this.value = value;
        this.protection_depth = protection_depth;
    }

    void write(ByteStream out) throws RecognitionException {
        if (line != 0)
            out.line(line);
        if (value != null)
            value.write(out);
        for (int i = 0; i < protection_depth; i++) {
            out.write(Opcodes.POP_HANDLER);
        }
        out.write(Opcodes.RETURN);
    }

    Stmt returns() {
        return this;
    }

}
